import 'package:flustars/flustars.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:get/get.dart';
import 'package:nft_shop/box/conteroller/box_details_controller.dart';
import 'package:nft_shop/box/model/models.dart';
import 'package:nft_shop/box/widget/purchase_instructions_widget.dart';
import 'package:nft_shop/login/controller/logic_controller.dart';
import 'package:nft_shop/login/controller/user_controller.dart';
import 'package:nft_shop/login/page/login_page.dart';
import 'package:nft_shop/market/model/models.dart';
import 'package:nft_shop/market/page/details/works_transaction_records_page.dart';
import 'package:nft_shop/market/page/order/buy_confirm_order_page.dart';
import 'package:nft_shop/market/page/userinfo/user_info_page.dart';
import 'package:nft_shop/market/widget/market_share_widget.dart';
import 'package:nft_shop/my/model/models.dart';
import 'package:nft_shop/my/view/cast_hint.dart';
import 'package:nft_shop/my/view/my_check_work_widget.dart';
import 'package:nft_shop/net/service_repository.dart';
import 'package:nft_shop/res/constant.dart';
import 'package:nft_shop/res/global.dart';
import 'package:nft_shop/util/other_utils.dart';
import 'package:nft_shop/widgets/load_image.dart';
import 'package:nft_shop/widgets/my_button.dart';
import 'package:nft_shop/widgets/my_scroll_view.dart';
import 'package:nft_shop/widgets/status_view.dart';

class BoxDetailsPage extends StatefulWidget {
  String id;

  //1单个盲盒详情 2整体铸造详情  3整体详情
  int type;
  bool isHidePayment;

  BoxDetailsPage(
      {Key? key,
      required this.id,
      required this.type,
      this.isHidePayment = false})
      : super(key: key);

  @override
  _BoxDetailsPageState createState() => _BoxDetailsPageState();
}

class _BoxDetailsPageState extends State<BoxDetailsPage>
    with TickerProviderStateMixin {
  late TabController _tabController;
  final PageController _pageController = PageController(initialPage: 0);
  late BoxDetailsConteroller _conteroller;
  TimerUtil? _timerUtil;
  ConfigNameDetail? article;

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    _tabController = TabController(vsync: this, length: 4);
    _conteroller = BoxDetailsConteroller.to;
    _conteroller.type = widget.type;
    _conteroller.getDataList(widget.id);
    getConfigNameDetail("pay_is_open");
    LoginLogic.to.getUserInfoData();
  }

  @override
  void dispose() {
    // TODO: implement dispose
    super.dispose();
    _tabController.dispose();
    cancelAddressTimer();
  }

  void cancelAddressTimer() {
    if (_timerUtil != null) {
      _timerUtil!.cancel();
      _timerUtil = null;
    }
  }

  void getConfigNameDetail(String name) async {
    try {
      List list = await ServiceRepository.getConfigNameDetail(name);
      list.forEach((element) {
        if (element.name.toString().trim() == name) {
          article = element;
        }
      });
    } catch (e, s) {}
    setState(() {});
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: PreferredSize(
        preferredSize: Size.fromHeight(48),
        child: AppBar(
          title: Text(
            "作品详情",
            style: TextStyle(
                fontSize: 16,
                color: Global.kTheme.textPrimary4,
                fontFamily: Global.mySemiboldFont),
          ),
          centerTitle: true,
          leading: IconButton(
            padding: const EdgeInsets.only(right: 12, top: 12, bottom: 12),
            icon: Image.asset(
              'assets/images/ic_back_black.png',
            ),
            onPressed: () {
              Get.back();
            },
          ),
          actions: [
            IconButton(
                icon: LoadAssetImage(
                  "na_share",
                  width: 16,
                  height: 16,
                ),
                onPressed: () {
                  showModalBottomSheet<void>(
                      context: context,

                      /// 禁止拖动关闭
                      enableDrag: false,

                      /// 使用true则高度不受16分之9的最高限制
                      isScrollControlled: true,
                      backgroundColor: Colors.transparent,
                      builder: (_) {
                        return MarketShareWidget(
                            info: GoodsInfo.fromJson(
                                _conteroller.boxInfo.toJson()));
                      });
                }),
          ],
        ),
      ),
      body: GetBuilder<BoxDetailsConteroller>(builder: (logic) {
        if (logic.status != LoadStatusType.success) {
          return StatusViews(logic.status);
        }
        if (logic.boxInfo.info!.isPresell == 1) {
          if (logic.boxInfo.info!.second! > 0) {
            cancelAddressTimer();
            _timerUtil =
                new TimerUtil(mTotalTime: logic.boxInfo.info!.second! * 1000);
            _timerUtil!.setOnTimerTickCallback((int tick) {
              if (tick == 0) {
                cancelAddressTimer();
                setState(() {
                  logic.boxInfo.info!.isPresell = 0;
                });
              }
              logic.setCountDownTime = Utils.constructTime(tick ~/ 1000);
            });
            // //开始倒计时
            _timerUtil!.startCountDown();
          }

          // if (DateUtil.getNowDateMs() <
          //     DateUtil.getDateMsByTimeStr(logic.boxInfo.info!.sellTime!)!) {
          //   _timerUtil = new TimerUtil(
          //       mTotalTime: DateUtil.getDateMsByTimeStr(
          //               logic.boxInfo.info!.sellTime!)! -
          //           DateUtil.getNowDateMs());
          //   _timerUtil!.setOnTimerTickCallback((int tick) {
          //     if (tick == 0) {
          //       cancelAddressTimer();
          //       setState(() {
          //         logic.boxInfo.info!.isPresell = 0;
          //       });
          //     }
          //     logic.setCountDownTime = Utils.constructTime(tick ~/ 1000);
          //   });
          //   // //开始倒计时
          //   _timerUtil!.startCountDown();
          // }
        }

        return MyScrollView(
          children: [
            topWidget(),
            Container(
              height: 10,
              color: Global.kTheme.colorLine,
            ),
            _framerWidget(),
            Container(
              height: 10,
              color: Global.kTheme.colorLine,
            ),
            Visibility(
                visible: _conteroller.boxInfo.info!.contractAddress != null,
                child: _basicInfoWidget()),
            Visibility(
                visible: _conteroller.boxInfo.info!.contractAddress != null,
                child: Container(
                  height: 10,
                  color: Global.kTheme.colorLine,
                )),
            _worksClassification(),
            Container(
              height: 10,
              color: Global.kTheme.colorLine,
            ),
            _detailsWidget(),
            Container(
              height: 10,
              color: Global.kTheme.colorLine,
            ),
            _worksDescribeWidget(),
            Container(
              height: 10,
              color: Global.kTheme.colorLine,
            ),
            widget.type != 2 ? transactionRecordWidget() : Container(),
            widget.type != 2
                ? Container(
                    height: 10,
                    color: Global.kTheme.colorLine,
                  )
                : Container(),
            purchaseInformationWidget(),
            Container(
              height: MediaQuery.of(context).padding.bottom,
            ),
          ],
          bottomButton: widget.isHidePayment
              ? Container()
              : (widget.type != 2
                  ? Container(
                      height: 50 + ScreenUtil.getBottomBarH(context),
                      color: Colors.white,
                      child: Column(
                        children: [
                          Container(
                            padding: EdgeInsets.only(
                                left: 20, right: 15, top: 3, bottom: 3),
                            child: Row(
                              mainAxisSize: MainAxisSize.min,
                              children: [
                                Text.rich(TextSpan(children: [
                                  TextSpan(
                                      text: "¥",
                                      style: TextStyle(
                                          fontSize: 12,
                                          color: Global.kTheme.textPrimary4)),
                                  TextSpan(
                                      text: logic.boxInfo.info!.basePrice ?? "",
                                      style: TextStyle(
                                          fontSize: 20,
                                          color: Global.kTheme.textPrimary4)),
                                ])),
                                Spacer(),
                                logic.boxInfo.info!.isPresell == 0
                                    ? Container(
                                        height: 38,
                                        width: 173,
                                        decoration: BoxDecoration(
                                          borderRadius:
                                              BorderRadius.circular(4),
                                        ),
                                        child: (article?.value == "false")
                                            ? MyButton(
                                                fontSize: 16,
                                                textColor:
                                                    Global.kTheme.textPrimary4,
                                                backgroundColor:
                                                    Color(0xFFEFEFEF),
                                                minHeight: 38,
                                                text: "敬请期待",
                                                onPressed: () {},
                                              )
                                            : MyButton(
                                                minHeight: 38,
                                                onPressed: logic.boxInfo.info!
                                                            .num ==
                                                        0
                                                    ? () {
                                                        EasyLoading.showToast(
                                                            "已售罄");
                                                      }
                                                    : () {
                                                        if (UserController
                                                            .to.isLogin) {
                                                          if (UserController
                                                                  .to
                                                                  .loginuser
                                                                  ?.member
                                                                  ?.realNameStatus !=
                                                              "2") {
                                                            EasyLoading
                                                                .showToast(
                                                                    "请实名认证后购买");
                                                            return;
                                                          }
                                                          Get.to(
                                                              BuyConfirmOrderPage(
                                                            goodsinfo: GoodsInfo
                                                                .fromJson(logic
                                                                    .boxInfo
                                                                    .toJson()),
                                                            type:
                                                                widget.type == 1
                                                                    ? 3
                                                                    : 1,
                                                          ));
                                                        } else {
                                                          Get.to(LoginPage());
                                                        }
                                                      },
                                                text:
                                                    logic.boxInfo.info!.num == 0
                                                        ? widget.type == 1
                                                            ? "已售罄"
                                                            : "发行结束"
                                                        : "购买盲盒",
                                                fontSize: 16,
                                                textColor:
                                                    logic.boxInfo.info!.num == 0
                                                        ? Global
                                                            .kTheme.textPrimary4
                                                        : Colors.white,
                                                backgroundColor:
                                                    logic.boxInfo.info!.num == 0
                                                        ? Color(0xFFEFEFEF)
                                                        : Global.kTheme
                                                            .colorBackground3,
                                              ),
                                      )
                                    : Container(
                                        height: 38,
                                        width: 210,
                                        decoration: BoxDecoration(
                                          color: Color(0xFFB2B2B2),
                                          borderRadius:
                                              BorderRadius.circular(4),
                                        ),
                                        child: Column(
                                          crossAxisAlignment:
                                              CrossAxisAlignment.center,
                                          children: [
                                            Text(
                                              "敬请期待",
                                              style: TextStyle(
                                                  fontSize: 15,
                                                  color: Global
                                                      .kTheme.textPrimary5,
                                                  fontWeight: FontWeight.w600),
                                            ),
                                            // Text("${logic.boxInfo.info!.sellTime??""}",style: TextStyle(fontSize: 12,color: Global.kTheme.textPrimary5,fontWeight: FontWeight.w600),),
                                            GetBuilder(
                                                init: BoxDetailsConteroller(),
                                                id: "countDownTime",
                                                builder:
                                                    (BoxDetailsConteroller c) {
                                                  return Text(
                                                    "${c.countDownTime} 后 开售",
                                                    style: TextStyle(
                                                        fontSize: 10,
                                                        color: Global.kTheme
                                                            .textPrimary5,
                                                        fontWeight:
                                                            FontWeight.w600),
                                                  );
                                                }),
                                          ],
                                        ),
                                      )
                              ],
                            ),
                          ),
                          Spacer(),
                        ],
                      ),
                    )
                  : Container(
                      height: 40,
                      margin: EdgeInsets.only(
                          top: 5,
                          left: 14,
                          right: 14,
                          bottom: 22 + ScreenUtil.getBottomBarH(context)),
                      decoration: BoxDecoration(
                        color: Global.kTheme.colorBackground3,
                        borderRadius: BorderRadius.circular(4),
                      ),
                      child: MyButton(
                        minHeight: 50,
                        onPressed: () {
                          Utils.showElasticDialog<void>(
                            context: context,
                            barrierDismissible: false,
                            builder: (BuildContext context) {
                              return CasrHintDialog(
                                  price: logic.boxInfo.info!.castPrice ?? "",
                                  id: "${logic.boxInfo.info!.id ?? ""}");
                            },
                          );
                        },
                        text: "确认铸造",
                        fontSize: 16,
                        textColor: Colors.white,
                        backgroundColor: Global.kTheme.colorBackground3,
                      ),
                    )),
        );
      }),
    );
  }

  ///切换tabbar
  void _onPageChange(int index) {
    _tabController.animateTo(index);
    _conteroller.changeHeight(index);
  }

  ///详情头部信息
  Widget topWidget() {
    double height = Get.width * 350 / 375;
    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      mainAxisAlignment: MainAxisAlignment.start,
      children: [
        InkWell(
          onTap: () {
            if (_conteroller.boxInfo.info!.thumb!.isEmpty) {
              return;
            }
            Utils.showElasticDialog<void>(
              context: context,
              builder: (BuildContext context) {
                return MyCheckWorkWidget(
                    _conteroller.boxInfo.info!.thumb ?? "");
              },
            );
          },
          child: LoadImage(
            _conteroller.boxInfo.info!.thumb ?? "",
            width: double.infinity,
            height: height,
            fit: BoxFit.fitHeight,
          ),
        ),
        Container(
          padding: EdgeInsets.symmetric(horizontal: 15, vertical: 10),
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            mainAxisAlignment: MainAxisAlignment.start,
            children: [
              Text(
                _conteroller.boxInfo.info!.title ?? "",
                style: TextStyle(
                    fontSize: 16,
                    color: Global.kTheme.textPrimary4,
                    fontFamily: Global.mySemiboldFont),
              ),
              SizedBox(
                height: 8,
              ),
              Row(
                children: [
                  issueView(
                      "发行", _conteroller.boxInfo.info!.allCount.toString()),
                  SizedBox(
                    width: 10,
                  )
                  // ,
                  // issueView(
                  //     "已售", _conteroller.boxInfo.info!.saleCount.toString()),
                ],
              ),
              SizedBox(
                height: 10,
              ),
              Row(
                crossAxisAlignment: CrossAxisAlignment.center,
                children: [
                  ClipRRect(
                      borderRadius: BorderRadius.circular(12),
                      child: LoadImage(
                        _conteroller.boxInfo.info!.portrait ?? "",
                        width: 24,
                        height: 24,
                      )),
                  SizedBox(
                    width: 5,
                  ),
                  Text(
                    _conteroller.boxInfo.info!.nickname ?? "header_img",
                    maxLines: 1,
                    overflow: TextOverflow.ellipsis,
                    style: TextStyle(
                        fontFamily: Global.mySemiboldFont,
                        fontSize: 14,
                        color: Global.kTheme.textPrimary0),
                  ),
                  SizedBox(
                    width: 5,
                  ),
                  Row(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      Column(
                        mainAxisSize: MainAxisSize.min,
                        children: [
                          SizedBox(
                            height: 4,
                          ),
                          LoadAssetImage(
                            "icon_creation",
                            width: 4,
                            height: 5,
                          ),
                        ],
                      ),
                      Text(
                        "创作者",
                        style: TextStyle(
                            fontFamily: Global.mySemiboldFont,
                            fontSize: 12,
                            color: Color(0xFF1D6AEC)),
                      ),
                      Column(
                        mainAxisSize: MainAxisSize.min,
                        children: [
                          SizedBox(
                            height: 10,
                          ),
                          LoadAssetImage(
                            "icon_creation",
                            width: 4,
                            height: 5,
                          ),
                        ],
                      ),
                    ],
                  ),
                  Spacer(),
                  InkWell(
                    onTap: () {
                      print(
                          "ID----${_conteroller.boxInfo.info!.framerMemberId ?? ""}");
                      Get.to(UserInfoPage(
                          ID: _conteroller.boxInfo.info!.framerMemberId ?? ""));
                    },
                    child: Container(
                      child: Row(
                        children: [
                          Text(
                            "Ta的主页",
                            style: TextStyle(
                                fontSize: 12,
                                color: Global.kTheme.textPrimary3,
                                fontWeight: FontWeight.w600),
                          ),
                          SizedBox(
                            width: 5,
                          ),
                          LoadImage(
                            "icon_arrows",
                            width: 12,
                            height: 12,
                          )
                        ],
                      ),
                    ),
                  ),
                ],
              )
            ],
          ),
        ),
        Visibility(
          visible: widget.type != 2
              ? (_conteroller.boxInfo.shouMemberList!.length != 0
                  ? true
                  : false)
              : false,
          child: Container(
            height: 40,
            padding: EdgeInsets.symmetric(horizontal: 15),
            child: ListView.builder(
              itemCount: _conteroller.boxInfo.shouMemberList!.length,
              scrollDirection: Axis.horizontal,
              itemBuilder: (_, index) {
                return collectionsView(index);
              },
            ),
          ),
        ),
        SizedBox(
          height: 5,
        ),
      ],
    );
  }

  ///收藏者
  Widget collectionsView(int index) {
    ShouMemberList shou = _conteroller.boxInfo.shouMemberList![index];
    return Row(
      mainAxisAlignment: MainAxisAlignment.start,
      mainAxisSize: MainAxisSize.min,
      crossAxisAlignment: CrossAxisAlignment.center,
      children: [
        ClipRRect(
            borderRadius: BorderRadius.circular(12),
            child: LoadImage(
              shou.portrait ?? "",
              width: 24,
              height: 24,
              holderImg: "header_img",
            )),
        SizedBox(
          width: 5,
        ),
        Text(
          shou.nickname ?? "",
          style: TextStyle(
              fontFamily: Global.mySemiboldFont,
              fontSize: 14,
              color: Global.kTheme.textPrimary0),
        ),
        SizedBox(
          width: 5,
        ),
        Row(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Column(
              mainAxisSize: MainAxisSize.min,
              children: [
                SizedBox(
                  height: 4,
                ),
                LoadAssetImage(
                  "icon_collection",
                  width: 4,
                  height: 5,
                ),
              ],
            ),
            Text(
              "收藏者",
              style: TextStyle(
                  fontFamily: Global.mySemiboldFont,
                  fontSize: 12,
                  color: Color(0xFFF17A47)),
            ),
            Column(
              mainAxisSize: MainAxisSize.min,
              children: [
                SizedBox(
                  height: 10,
                ),
                LoadAssetImage(
                  "icon_collection",
                  width: 4,
                  height: 5,
                ),
              ],
            ),
          ],
        ),
        SizedBox(
          width: 25,
        )
      ],
    );
  }

  ///基本信息
  Widget _basicInfoWidget() {
    return Padding(
      padding: const EdgeInsets.symmetric(
        horizontal: 14,
      ),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          cellTitleWidget("链上信息"),
          _infoTextItem("编      号",
              "#${_conteroller.boxInfo.info!.code ?? ""}/${_conteroller.boxInfo.info!.allCount ?? ""}"),
          _infoTextItem(
              "合约地址",
              omitAddress(_conteroller.boxInfo.info!.contractAddress ??
                  (_conteroller.boxInfo.info!.contractAddress ?? "")),
              right: "复制地址", onTap: () {
            if (_conteroller.boxInfo.info!.contractAddress!.length != 0) {
              ClipboardData data = new ClipboardData(
                  text: _conteroller.boxInfo.info!.contractAddress ??
                      (_conteroller.boxInfo.info!.contractAddress ?? ""));
              Clipboard.setData(data);
              EasyLoading.showToast("复制成功");
            }
          }, copy: () {
            ClipboardData data = new ClipboardData(
                text: _conteroller.boxInfo.info!.contractAddress ?? "");
            Clipboard.setData(data);
            EasyLoading.showToast("复制成功");
          }),
          _infoTextItem("链上标识", _conteroller.boxInfo.info!.chain_mark ?? ""),
          _infoTextItem("发布时间", _conteroller.boxInfo.info!.create_time ?? ""),
          SizedBox(
            height: 15,
          ),
        ],
      ),
    );
  }

  ///创作者介绍
  Widget _framerWidget() {
    return Container(
      padding: EdgeInsets.symmetric(horizontal: 14),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          cellTitleWidget("创作者介绍"),
          Row(
            mainAxisAlignment: MainAxisAlignment.start,
            children: [
              ClipRRect(
                  borderRadius: BorderRadius.circular(21),
                  child: LoadImage(
                    _conteroller.boxInfo.info!.portrait ?? "header_img",
                    width: 42,
                    height: 42,
                  )),
              SizedBox(
                width: 5,
              ),
              Expanded(
                child: Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    Text(
                      _conteroller.boxInfo.info!.nickname ?? "",
                      maxLines: 1,
                      overflow: TextOverflow.ellipsis,
                      style: TextStyle(
                          fontSize: 14,
                          color: Global.kTheme.textPrimary0,
                          fontFamily: Global.mySemiboldFont),
                    ),
                    InkWell(
                      onTap: () {
                        ClipboardData data = new ClipboardData(
                            text: _conteroller
                                    .boxInfo.info!.framerAccountAddress ??
                                "");
                        Clipboard.setData(data);
                        EasyLoading.showToast("复制成功");
                      },
                      child: Row(
                        children: [
                          Text(omitAddress(
                              _conteroller.boxInfo.info!.framerAccountAddress ??
                                  "")),
                          SizedBox(
                            width: 4,
                          ),
                          LoadImage(
                            "my_copy",
                            width: 16,
                            height: 16,
                          ),
                        ],
                      ),
                    )
                  ],
                ),
              )
            ],
          ),
          SizedBox(
            height: 10,
          ),
          Text(
            _conteroller.boxInfo.info!.introduce ?? "",
            style: TextStyle(
                fontSize: 12,
                color: Global.kTheme.inputHint1,
                fontFamily: Global.mySemiboldFont),
          ),
          SizedBox(
            height: 10,
          ),
        ],
      ),
    );
  }

  ///作品描述
  Widget _worksClassification() {
    return Container(
        padding: EdgeInsets.symmetric(horizontal: 14),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            cellTitleWidget("作品描述"),
            Container(
              height: 40,
              child: Row(
                mainAxisSize: MainAxisSize.min,
                children: [
                  Text(
                    "您可能抽到以下作品中的",
                    style: TextStyle(
                        fontSize: 12,
                        color: Global.kTheme.inputHint1,
                        fontFamily: Global.mySemiboldFont),
                  ),
                  Text(
                    "1",
                    style: TextStyle(
                        fontSize: 12,
                        color: Global.kTheme.textPrimary4,
                        fontFamily: Global.mySemiboldFont),
                  ),
                  Text(
                    "个",
                    style: TextStyle(
                        fontSize: 12,
                        color: Global.kTheme.inputHint1,
                        fontFamily: Global.mySemiboldFont),
                  ),
                ],
              ),
            ),
            Container(
              height: _conteroller.boxInfo.specialBlindBoxList!.length * 70,
              child: ListView.builder(
                itemCount: _conteroller.boxInfo.specialBlindBoxList!.length,
                physics: const NeverScrollableScrollPhysics(),
                itemBuilder: (_, index) {
                  return _worksItem(index);
                },
              ),
            ),
            SizedBox(
              height: 10,
            ),
          ],
        ));
  }

  Widget _worksItem(int index) {
    SpecialBlindBoxList model =
        _conteroller.boxInfo.specialBlindBoxList![index];
    return Container(
      height: 60,
      margin: EdgeInsets.symmetric(vertical: 5),
      padding: EdgeInsets.symmetric(horizontal: 15, vertical: 10),
      decoration: BoxDecoration(
        color: Color(0xFFF8F8F8),
        borderRadius: BorderRadius.circular(4),
      ),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Text(
            model.title ?? "",
            style: TextStyle(
                fontSize: 12,
                color: Global.kTheme.textPrimary1,
                fontFamily: Global.mySemiboldFont),
          ),
          SizedBox(
            height: 5,
          ),
          Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
              Text.rich(TextSpan(children: [
                TextSpan(
                    text: "概率 ",
                    style: TextStyle(
                        fontSize: 12,
                        color: Global.kTheme.textPrimary3,
                        fontFamily: Global.mySemiboldFont)),
                TextSpan(
                    text:
                        "${NumUtil.multiply(double.parse(model.probability ?? "0"), 100).toStringAsFixed(2)}%",
                    style: TextStyle(
                        fontSize: 12,
                        color: Global.kTheme.textPrimary4,
                        fontFamily: Global.mySemiboldFont)),
              ])),
              Text.rich(TextSpan(children: [
                TextSpan(
                    text: "原价 ",
                    style: TextStyle(
                        fontSize: 12,
                        color: Global.kTheme.textPrimary3,
                        fontFamily: Global.mySemiboldFont)),
                TextSpan(
                    text: "¥ ${model.basePrice}",
                    style: TextStyle(
                        fontSize: 12,
                        color: Global.kTheme.textPrimary4,
                        fontFamily: Global.mySemiboldFont)),
              ])),
            ],
          )
        ],
      ),
    );
  }

  //细节展示
  Widget _detailsWidget() {
    return Padding(
        padding: EdgeInsets.symmetric(horizontal: 14),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            cellTitleWidget("细节展示"),
            LoadImage(
              _conteroller.boxInfo.info!.detail ?? "",
              width: Get.width,
              fit: BoxFit.fitWidth,
            ),
            SizedBox(
              height: 15,
            ),
          ],
        ));
  }

  ///作品描述
  Widget _worksDescribeWidget() {
    return Container(
        padding: EdgeInsets.symmetric(horizontal: 14),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            cellTitleWidget("作品故事"),
            Text(
              _conteroller.boxInfo.info!.story ?? "",
              style: TextStyle(
                  fontSize: 12,
                  color: Global.kTheme.inputHint1,
                  fontFamily: Global.mySemiboldFont),
            ),
            SizedBox(
              height: 15,
            ),
          ],
        ));
  }

  String omitAddress(String address, {int len = 4}) {
    if (address == null || address.isEmpty) return "";
    if (address.length > (len * 2)) {
      return address.substring(0, len) +
          '...' +
          address.substring(address.length - len, address.length);
    }
    return address;
  }

  //标题
  Widget cellTitleWidget(String title) {
    return Container(
      padding: EdgeInsets.symmetric(vertical: 14),
      child: Text(
        title,
        style: TextStyle(
            fontSize: 14,
            fontFamily: Global.mySemiboldFont,
            color: Global.kTheme.textPrimary1),
      ),
    );
  }

  ///抽取记录
  Widget transactionRecordWidget() {
    double height = 0;
    if (_conteroller.boxInfo.specialBlindBoxLog!.length == 0) {
      height = 224;
    } else if (_conteroller.boxInfo.specialBlindBoxLog!.length <= 3) {
      height = _conteroller.boxInfo.specialBlindBoxLog!.length * 63 + 40;
    } else {
      height = 3 * 63 + 40;
    }
    return Container(
      height: height,
      padding: EdgeInsets.symmetric(horizontal: 15),
      child: Column(
        children: [
          InkWell(
            onTap: () => Get.to(WorksTransactionRecordsPage(
              type: 2,
              id: _conteroller.boxInfo.info!.id!,
            )),
            child: Container(
              height: 40,
              child: Row(
                children: [
                  Text(
                    "抽取记录",
                    style: TextStyle(
                        fontSize: 14,
                        color: Global.kTheme.textPrimary1,
                        fontFamily: Global.mySemiboldFont),
                  ),
                  Spacer(),
                  Text(
                    "更多抽取记录",
                    style: TextStyle(
                        fontFamily: Global.mySemiboldFont,
                        fontSize: 12,
                        color: Global.kTheme.textPrimary3),
                  ),
                  SizedBox(
                    width: 5,
                  ),
                  LoadAssetImage(
                    "icon_arrows",
                    width: 12,
                    height: 12,
                  ),
                ],
              ),
            ),
          ),
          Expanded(child: Builder(builder: (context) {
            if (_conteroller.boxInfo.specialBlindBoxLog!.length == 0) {
              return StatusViews(LoadStatusType.empty);
            }
            return ListView.builder(
                physics: NeverScrollableScrollPhysics(), //禁止滑动
                itemCount: _conteroller.boxInfo.specialBlindBoxLog!.length > 3
                    ? 3
                    : _conteroller.boxInfo.specialBlindBoxLog!.length,
                itemBuilder: (context, int index) {
                  return transactionItem(
                      _conteroller.boxInfo.specialBlindBoxLog![index]);
                });
          })),
        ],
      ),
    );
  }

  Widget transactionItem(SpecialBlindBoxLog model) {
    return Container(
      padding: EdgeInsets.only(
        top: 15,
        bottom: 13,
      ),
      decoration: BoxDecoration(
          border: Border(
        bottom: Divider.createBorderSide(context,
            color: Global.kTheme.colorLine, width: 1),
      )),
      child: Row(
        children: [
          Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Text(
                model.nickname ?? "",
                style: TextStyle(
                    fontSize: 12,
                    color: Global.kTheme.textPrimary1,
                    fontFamily: Global.mySemiboldFont),
              ),
              SizedBox(
                height: 1,
              ),
              Text(
                model.createTime ?? "",
                style: TextStyle(
                    fontSize: 12,
                    color: Global.kTheme.textPrimary3,
                    fontFamily: Global.mySemiboldFont),
              ),
            ],
          ),
          Spacer(),
          Text(
            "抽中${model.title}",
            style: TextStyle(
                fontSize: 12,
                color: Global.kTheme.textPrimary1,
                fontFamily: Global.mySemiboldFont),
          ),
        ],
      ),
    );
  }

  ///购买须知
  Widget purchaseInformationWidget() {
    return Container(
      padding: EdgeInsets.symmetric(horizontal: 15, vertical: 10),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Text(
            "购买须知",
            style: TextStyle(
                fontSize: 14,
                color: Global.kTheme.textPrimary1,
                fontFamily: Global.mySemiboldFont),
          ),
          SizedBox(
            height: 9,
          ),
          // Text(
          //   "数字藏品为虚拟数字商品，而非实物，仅限经实名认证为年满14周岁的中国大陆用户购买。数字藏品的版权由发行方或原创者拥有，除另行取得版权拥有者书面同意外，用户不得将数字藏品用于任何商业用途。本商品一经售出，不支持退换。请勿对数字藏品进行炒作、场外交易、欺诈，或以任何其他非法方式进行使用",
          //   style: TextStyle(
          //       fontSize: 12,
          //       color: Global.kTheme.inputHint1,
          //       fontFamily: Global.mySemiboldFont),
          // ),
          PurchaseInWidget()
        ],
      ),
    );
  }

  ///藏品类型
  Widget _objectType(String state) {
    return Container(
      height: 20,
      decoration: BoxDecoration(
        color: Global.kTheme.colorBackground3,
      ),
      padding: EdgeInsets.symmetric(horizontal: 8, vertical: 1),
      child: Text(
        state,
        style: TextStyle(
            color: Global.kTheme.textPrimary5,
            fontSize: 12,
            fontFamily: Global.mySemiboldFont),
      ),
    );
  }

  //数量
  Widget issueView(String left, String right) {
    if (right.length == 0 || right == null) {
      right = "0";
    }
    return Row(
      children: [
        Container(
          color: Global.kTheme.colorBackground3,
          padding: EdgeInsets.symmetric(horizontal: 5, vertical: 2),
          child: Text(
            left,
            style: TextStyle(
                fontSize: 12,
                color: Global.kTheme.textPrimary5,
                fontFamily: Global.mySemiboldFont),
          ),
        ),
        Container(
          color: Color(0xFFB6B6B6),
          padding: EdgeInsets.symmetric(horizontal: 6, vertical: 2),
          child: Text(
            right,
            style: TextStyle(
                fontSize: 12,
                color: Global.kTheme.textPrimary5,
                fontFamily: Global.mySemiboldFont),
          ),
        ),
      ],
    );
  }
}

///基本信息Item
Widget _infoTextItem(
  String title,
  String content, {
  String right = "",
  VoidCallback? onTap,
  VoidCallback? copy,
}) {
  return Container(
    padding:
        title == "所属专辑" ? EdgeInsets.only(top: 5) : EdgeInsets.only(top: 15),
    child: Row(
      children: [
        Text(
          title,
          style: TextStyle(
              fontSize: 12,
              color: Global.kTheme.inputHint1,
              fontFamily: Global.mySemiboldFont),
        ),
        SizedBox(
          width: 15,
        ),
        Expanded(
          child: Row(
            children: [
              InkWell(
                  onTap: copy,
                  child: Container(
                      child: Text(
                    content,
                    style: TextStyle(
                      fontSize: 12,
                      color: Global.kTheme.textPrimary1,
                      fontFamily: Global.mySemiboldFont,
                    ),
                  ))),
              Spacer(),
              InkWell(
                onTap: onTap,
                child: Row(
                  mainAxisSize: MainAxisSize.min,
                  children: [
                    right.length != 0
                        ? Text(
                            right,
                            style: TextStyle(
                                fontSize: 12,
                                color: Global.kTheme.textPrimary3,
                                fontFamily: Global.mySemiboldFont),
                          )
                        : Container(),
                    right.length != 0
                        ? SizedBox(
                            width: 3,
                          )
                        : Container(),
                    Visibility(
                      visible: right.length != 0,
                      child: LoadImage(
                        "icon_arrows",
                        width: 12,
                        height: 12,
                      ),
                    ),
                  ],
                ),
              ),
            ],
          ),
        )
      ],
    ),
  );
}
